﻿@model Easy.CMS.List.ViewModel.ListTops_PopModal_ViewModel
@using Easy.Web.CMS.Data;
@{
    Script.Reqiured("List").AtHead();

    if (!Model.Widget.DetailPageUrl.IsNullOrEmpty())
    {
        Model.Widget.DetailPageUrl = Url.Content(Model.Widget.DetailPageUrl);
    }
}

<script>
    $(function () {
        load();
        var btn = $("#" + '@Model.Widget.ID');
        btn.click(function () {
            var page = $(btn).attr('ohref');
            var url ='@Urls.CdnHost/' + page + "?FormId=" + '@Model.Widget.FormId' + "&FormCode=" + '@Model.Widget.FormCode' + "&AppId"+'@Model.Widget.AppId'+'&oper=add&FormType=&listId=&btncode=&cms=';
            layer.open({
                type: 2,
                title: '文章编辑',
                shadeClose: true,
                shade: 0.8,
                area: ['950px', '90%'],
                content:url
            });
        });
    });

    function loadData() {
        layer.closeAll();
        load();
    }

    function load() {
        var _listId = '@Model.Widget.ListId',
            _formCode = 'DefineCondition',
            top = '@Model.Widget.Tops' || 5;

        if (_listId && _listId.length > 0) {
            var d = [{ "Id": "", "opt": "select", "name": _formCode },
           { "item": { "Name": "list_id", "Operation": "eq", "Value": _listId, "ValueType": "string" } }];

            doajaxasync("@Urls.ApiHost/api/mp/list/findfirst", d, false, function (b) {

                if (b && b.length > 0) {
                    var data = JSON.parse(b);
                    if (data) {
                        var defConditions = data['define'];
                        // [{"ValueType":"Select","Name":"InfoColumn","Value":"工作简报","Operation":"EQ"}]
                        if (defConditions && defConditions.length > 0) {
                            var conditions = JSON.parse(defConditions);

                            var typeJson = {};
                            typeJson.CollectionName = '@Model.Widget.FormCode';
                            typeJson.SortName = "createtime";       //_id
                            typeJson.SortType = "desc";             // DESC
                            typeJson.JsonData = JSON.stringify(conditions);
                            typeJson.PageSize = top;
                            typeJson.PageIndex = 1;

                            doajax1async("@Urls.ApiHost/api/mp/list/findpageforsql", typeJson, true, function (b1) {
                                $("#listpop .list-group").empty();
                                if (b1 && b1.length > 0) {
                                    var data = JSON.parse(b1);
                                    if (data && data.length > 0) {
                                        var html = '';
                                        $.each(data, function (idx, item) {
                                            var Id = item["Id"];
                                            var detailUrl = '@Model.Widget.DetailPageUrl';
                                            var title = '';
                                            var date = '';
                                            if ('@Model.Columns[0]') {
                                                title = item['@Model.Columns[0]'];
                                            }
                                            if ('@Model.Columns[1]') {
                                                date = item['@Model.Columns[1]'];
                                            }

                                            var url = detailUrl + '/list-' + Id;  // @*@Url.PathContent(Url.ListDetailUrl(Model.Widget.DetailPageUrl, Id))@*@

                                            html += '<a title="' + title + '" class="list-group-item" href="' + url + '" target="_blank">';
                                            html += '<li style="overflow-x: hidden;text-overflow: ellipsis;white-space: nowrap;list-style-type:none;">';
                                            html += '<span class="list-group-item-text">';
                                            html += '<font size="4">&bull; </font>' + cutstr(title, @Model.Widget.ItemLength) + '</span>';
                                            html += '<span style="float:right;margin-top:3px;">' + date + '</span>';
                                            html += '</li>';
                                            html += '</a>';

                                        });
                                        $("#listpop .list-group").append(html);
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    }

</script>

<div id="listpop" class="listtops">
     <div class="list-group">

     </div>
 </div>

